<template>
	<view>
		<view class="select_warp">
			<view class="topbox">
				<view class="tab_list">
					<view 
						class="tab_li"
						v-for="(item,index) in readList"
						:key="index"
						:class="{'tab_li_active': item.id == readIndex}"
						@click="changeTab(item)"
					>{{item.name}}</view>
				</view>
			</view>
			
			<view class="searchbox">
				<view class="searchtext" @click="showSearch = true">筛选<view class="iconfont icon-shaixuan"></view></view>
			</view>
			<view class="warpbox" v-if="showSearch" @tap.stop="showSearch = false">
				<scroll-view scroll-y class="scrollbox" style="height:800rpx;background:#fff;" >
					<!--筛选模块  -->
					<view class="screen_content"  @tap.stop.prevent>
						<view class="fir_li">
							<view class="li_label">提交人</view>
							<picker @change="changeType" :value="typeIndex" :range="typeList" :range-key="'name'">
								<view class="li_box">
									<view class="form_right">
										<view :class="typeList[typeIndex] ? 'valueactive' : '' ">{{typeList[typeIndex] ? typeList[typeIndex].name : '点击选择'}}</view>
										<view class="iconfont icon-arrows_right"></view>
									</view>
								</view>
							</picker>
						</view>
						<view class="fir_li">
							<view class="li_label">报告类型</view>
							<picker @change="changeWorkType" :value="workIndex" :range="workList" :range-key="'name'">
								<view class="li_box">
									<view class="form_right">
										<view :class="workList[workIndex] ? 'valueactive' : '' ">{{workList[workIndex] ? workList[workIndex].name : '点击选择'}}</view>
										<view class="iconfont icon-arrows_right"></view>
									</view>
								</view>
							</picker>
						</view>
					</view>
				</scroll-view>
				<view class="button_bottom">
					<view @tap.stop="reset">重置</view>
					<view @tap.stop="sureQuery">确定</view>
				</view>
			</view>
		</view>
		<view>
			<view class="work_li" v-for="(item,index) in list" :key="index" @click="jumpDetail(item)">
				<view class="li_key" v-if="item.is_read != 1"></view>
				<view class="li_left">
					<image :src="BASE_IMG_URL+'headImg.png'" class="li_img" mode=""></image>
					<view class="">
						<view class="li_name">{{item.staff_name}} <text style="font-size:24rpx;color:#999;margin-left:15rpx">{{item.post}}</text> </view>
						<view class="li_post">{{item.logdate}}</view>
					</view>
				</view>
				<view class="li_right">
					<view class="tatus firbg" v-if="item.log_type == '1'">日报</view>
					<view class="tatus secbg" v-if="item.log_type == '2'">周报</view>
					<view class="tatus thrbg" v-if="item.log_type == '3'">月报</view> 
				</view>
			</view>
			<u-loadmore v-if="list.length == 0" status="nomore"></u-loadmore>
		</view>
		
		<!-- 创建用户图标 -->
		<view class="icon_creat" @click="createWork">
			<image :src="BASE_IMG_URL+'1.png'"></image>
		</view>
	</view>
</template>

<script>
	import { netWorkreportList } from '@/api/index.js'
	import { netSelect, netSearchStaffList } from '@/api/kehu.js'
	import { BASE_IMG_URL } from '@/util/api.js'
	
	export default{
		data(){
			return{
				BASE_IMG_URL:BASE_IMG_URL,
				list:[],
				page:1,
				totalPage:1,
				showSearch:false,
				typeList:['全部客户','我的客户','下属负责的客户'],
				typeIndex:null,
				workList:[],
				workIndex:null,
				readList:[{id:0,name:'全部'},{id:1,name:'已读'},{id:2,name:'未读'}],
				readIndex:0,
				permission:{},   //权限
			}
		},
		onShow() {
			this.list = []
			this.page = 1
			this.getList()
			//获取筛选条件
			this.getSelect()
			//获取 归属人
			this.getPeopel()
			
			this.permission = getApp().globalData.permission
		},
		onReachBottom() {
			if(this.page >= this.totalPage){
				return
			}
			this.page ++
			this.getList()
		},
		methods:{
			changeTab(item) {
				this.readIndex = item.id
				this.page = 1
				this.list = []
				this.getList()
			},
			//获取归属人
			getPeopel() {
				netSearchStaffList().then(res=>{
					this.typeList = res.data
				})
			},
			//获取筛选条件
			getSelect() {
				netSelect().then(res=>{
					this.workList = res.data['WORKLOG_TYPE']
				})
			},
			getList() {
				let params = {
					page:this.page,
					is_read:this.readIndex,
					staff_id:this.typeList[this.typeIndex] ? this.typeList[this.typeIndex].id : null,
					log_type:this.workIndex?this.workList[this.workIndex].id : null
				}
				netWorkreportList(params).then(res=>{
					this.list = this.list.concat(res.data.list)
					this.totalPage = res.data.totalPage
				})
			},
			jumpDetail(item) {
				uni.navigateTo({
					url:'/pages/workreport/workDetail?id='+item.id
				})
			},
			//修改 报告状态
			changeRead(e) {
				this.readIndex = e.detail.value
			},
			changeType(e) {
				this.typeIndex = e.detail.value
			},
			changeWorkType(e) {
				this.workIndex = e.detail.value
			},
			//重置
			reset() {
				this.readIndex = null
				this.typeIndex = null
				this.workIndex = null
				this.showSearch = false
				this.list = []
				this.page = 1
				this.totalPage = 1
				this.getList()
			},
			sureQuery() {
				this.page = 1
				this.totalPage = 1
				this.list = []
				this.showSearch = false
				this.getList()
			},
			//创建  工作报告
			createWork() {
				console.log('ss');
				uni.navigateTo({
					url:'/pages/workreport/addReports'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.topbox{
		width:750rpx;
		height:80rpx;
		background:#fff;
		.tab_list{
			padding:0 24rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;
			.tab_li{
				width:120rpx;
				font-size:30rpx;
				color:#666;
				height:80rpx;
				margin-right:40rpx;
				line-height: 80rpx;
				flex-shrink: 0;
				text-align: center;
			}
			.tab_li_active{
				color:#000;
				position: relative;
				&::after{
					content:'';
					width:60rpx;
					height:6rpx;
					background:#03aa96;
					position: absolute;
					bottom:0;
					left:50%;
					transform: translateX(-50%);
				}
			}
		}
	}
	.icon_creat {
		position: fixed;
		z-index: 1;
		bottom: 100rpx;
		right: 100rpx;
	
		image {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
		}
	}
	.firbg{
		background:#AF99FE;
	}
	.secbg{
		background:#FBB545;
	}
	.thrbg{
		background:#4AD49D;
	}
	.forbg{
		background:#FF6E7F;
	}
	.fivbg{
		background:#54B1F7;
	}
	
	.valueactive{
		color:#333;
	}
	.rediowarp{
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
		label{
			display: flex;
			justify-content: flex-start;
			margin-right:24rpx;
			align-items: center;
		}
		radio{
			transform: scale(0.7);
		}
	}
	.work_li{
		width:702rpx;
		background:#fff;
		border-radius: 10rpx;
		padding:30rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin:0 auto 24rpx;
		position: relative;
		.li_key{
			position: absolute;
			right:5rpx;
			top:5rpx;
			width:20rpx;
			height:20rpx;
			border-radius: 50%;
			background:red;
		}
		.li_left{
			display: flex;
			justify-content: flex-start;
			align-items: center;
			font-size:26rpx;
			color:#333;
			.li_img{
				width:80rpx;
				height:80rpx;
				border-radius: 50%;
				margin-right:15rpx;
			}
			.li_name{
				font-size:26rpx;
				color:#333;
				margin-bottom:15rpx;
			}
		}
		.li_right{
			.tatus{
				font-size:24rpx;
				color:#fff;
				width:110rpx;
				height:55rpx;
				border-radius: 10rpx;
				text-align: center;
				line-height: 55rpx;
			}
		}
	}
	.select_warp{
		z-index: 9;
	}
	.searchbox{
		display: flex;
		justify-content: flex-end;
		margin:24rpx;
		.searchtext{
			display: flex;
			justify-content: center;
			align-items: center;
			font-size:24rpx;
			color:#333;
			padding:5rpx 23rpx;
			background:#fff;
			border-radius: 5rpx;
			box-shadow: 2rpx 2rpx 50rpx rgba(0,0,0,0.1);
		}
	}
	.warpbox{
		position: fixed;
		width:750rpx;
		left:0;
		// #ifdef MP-WEIXIN
		top:0rpx;
		// #endif
		// #ifdef H5
		top:80rpx;
		// #endif
		bottom:0;
		z-index: 2;
		background:rgba(0,0,0,0.7);
		.screen_content {
			width:702rpx;
			z-index: 2;
			border-top:1rpx solid #CCCCCC;
			background-color: #fff;
			padding:24rpx;
			.fir_li{
				margin-bottom:20rpx;
				.li_label{
					font-size:28rpx;
					color:#333333;
					margin-bottom:15rpx;
				}
				.li_box{
					border-radius: 15rpx;
					border:1rpx solid #CCCCCC;
					height:60rpx;
					padding:0 35rpx;
					line-height: 60rpx;
				}
				.form_right {
					display: flex;
					color: #999;
					justify-content: space-between;
					image {
						width: 40rpx;
						height: 40rpx;
						margin: 28rpx 5rpx 0 0;
					}
					
				}
			}
		}
		.button_bottom {
			display: flex;
			width: 100%;
			height: 90rpx;
			background-color: #fff;
			line-height: 90rpx;
			text-align: center;
			font-size: 32rpx;
			:first-child {
				flex: 1;
				color: #03aa96;
				border-top:1rpx solid #CCCCCC;
			}
			:last-child {
				flex: 1;
				background-color: #03aa96;
				color: #fff;
			}
		}
	}
</style>
